import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  nickname: localStorage.getItem('nickname') ||  "",
  avator: localStorage.getItem('avator') ||  "",
  token: localStorage.getItem('token') ||  "",
};

const userSlice = createSlice({
  name: "user",
  initialState,
  reducers: {
    loginSuccess(state, action) {
      state.avator = action.payload.avator;
      state.nickname = action.payload.nickname;
      state.token = action.payload.token;
    },
    loginFail(state) {
      state.avator = "";
      state.nickname = "";
      state.token = "";
    },
  },
});
export const { loginSuccess, loginFail } = userSlice.actions;
export default userSlice;
